package org.springblade.modules.repair.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springblade.modules.repair.vo.TaskStatusVO;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description 审批流程状态,对应blade_business_approve表approve_status
 * @Author ysq
 * @Date 2021/12/7
 **/
@Getter
@AllArgsConstructor
public enum ApproveStatusEnum {

	PENDING(1,"待审核"),

	PASSED(2,"审核通过"),

	REJECT(3,"审核不通过"),

	CANCEL(4,"已撤回"),

	RETURN(5, "审核退回");
	final int id;

	final String name;

	/**
	 * 根据id获取枚举name值
	 * @param id 枚举id
	 * @return name值
	 */
	public static String getName(Integer id){
		if (id == null) {
			return null;
		}

		ApproveStatusEnum[] values = ApproveStatusEnum.values();
		for(ApproveStatusEnum approveStatusEnum :values){
			Integer enumId = approveStatusEnum.getId();
			if(id.equals(enumId)){
				return approveStatusEnum.getName();
			}
		}
		return null;
	}

	public static ApproveStatusEnum getByStatus(Integer status) {
		for (ApproveStatusEnum constants : values()) {
			if (constants.getId() == status) {
				return constants;
			}
		}
		return null;
	}

	/**
	 * 根据类型获取任务状态集合
	 * @return
	 */
	public static List<TaskStatusVO> getTaskStatus() {
		List<TaskStatusVO> list = new ArrayList<>();
		ApproveStatusEnum[] taskStatuses = ApproveStatusEnum.values();
		for (ApproveStatusEnum task : taskStatuses) {
			TaskStatusVO taskStatus = new TaskStatusVO();
			taskStatus.setStatus(task.getId());
			taskStatus.setName(task.getName());
			list.add(taskStatus);
		}
		return list;
	}

}
